package com.androidhuman.example.mapsv2example;

import java.util.regex.Pattern;

import android.text.Editable;
import android.text.InputFilter;
import android.text.Spanned;
import android.text.TextWatcher;
import android.widget.EditText;

public class TextChecker {
	public static String purifyString(String string){
		if(string==null)return null;
		
		String purifyString="";
		String temp="";
		for(int i=0; i<string.length(); i++)
		{
			temp=string.substring(i, i+1);
			if((temp.charAt(0)>=45 && temp.charAt(0)<58) || temp.charAt(0)==32 || temp.charAt(0)==58)
			{purifyString+=temp;}
		}
		return purifyString;
	}
}

class Alpha_Num_OK implements InputFilter
{
	@Override
	public CharSequence filter(CharSequence source, int start, int end,
			Spanned dest, int dstart, int dend) {
		// TODO Auto-generated method stub
		Pattern ps = Pattern.compile("^[a-zA-Z0-9]+$");
		if (!ps.matcher(source).matches()) {
			return "";
		} 
		return null;
	} 
};

class Alpha_OK implements InputFilter
{
	@Override
	public CharSequence filter(CharSequence source, int start, int end,
			Spanned dest, int dstart, int dend) {
		// TODO Auto-generated method stub
		Pattern ps = Pattern.compile("^[a-zA-Z]+$");
		if (!ps.matcher(source).matches()) {
			return "";
		} 
		return null;
	} 
};

class GhostCharacterShield implements InputFilter
{
	@Override
	public CharSequence filter(CharSequence source, int start, int end,
			Spanned dest, int dstart, int dend) {
		// TODO Auto-generated method stub
		Pattern ps = Pattern.compile("^[墸彁閠]+$");
		if (ps.matcher(source).matches()) {
			return "";
		} 
		return null;
	} 
};

//m_editView.addTextChangedListener(new TextWatcher() {
class cusTextWatcher implements TextWatcher
{
	String strCur;
	EditText editText;
	int length;
	public cusTextWatcher(EditText editText, int length)
	{
		this.editText=editText;
		this.length=length;
	}
	public void onTextChanged(CharSequence s, int start, int before, int count) {
		if (s.length() > length) {
			editText.setText(strCur);
			editText.setSelection(start);
		} else {
		}
	}
	public void beforeTextChanged(CharSequence s, int start, int count, int after) {
		strCur = s.toString();
	}
	@Override
	public void afterTextChanged(Editable s) {
	}
}